﻿using System;
using BizElements.Core;

namespace BizElements.BusinessLayer
{
    /// <summary>EntityDaoFactory facade/utility class that simplifies creation of custom <see cref="BizElements.Core.IEntityDAO"/> objects.</summary>
    public static class DAL
    {
        #region GetDao.

        /// <summary>Gets the most optimal DAO that will work the given entity.</summary>
        /// <typeparam name="TEntity">Entity class.</typeparam>
        /// <param name="conn">Connection context DAO will use. If null, default DAO settings are used.</param>
        /// <returns>IEntityDAO object.</returns>
        public static IEntityDAO GetDao<TEntity>(IConnectionProvider conn)
            where TEntity : IEntity, new()
        {
            return EntityDaoFactory.GetEntityDAO(new TEntity(), conn);
        }

        /// <summary>Gets the most optimal DAO that will work the given entity.</summary>
        /// <param name="entity">Entity with wich the returned DAO works with.</param>
        /// <param name="conn">Connection context DAO will use. If null, default DAO settings are used.</param>
        /// <returns>IEntityDAO object.</returns>
        public static IEntityDAO GetDao(IEntity entity, IConnectionProvider conn)
        {
            return EntityDaoFactory.GetEntityDAO(entity, conn);
        }

        /// <summary>Gets the most optimal DAO that will work the given table/view.</summary>
        /// <param name="table">Table/view to be accesses by returned DAO.</param>
        /// <param name="conn">Connection context DAO will use. If null, default DAO settings are used.</param>
        /// <returns>IEntityDAO object.</returns>
        public static IEntityDAO GetDao(IDbTable table, IConnectionProvider conn)
        {
            return EntityDaoFactory.GetEntityDAO(table.NewEntity(), conn);
        }

        #endregion
    }
}
